package com.wz.concurrent;

import java.util.concurrent.SynchronousQueue;

public class SynchronousQueueTest {

	public static void main(String[] args) {
		final SynchronousQueue<String> test = new SynchronousQueue<String>();
		new Thread(new Runnable() {

			@Override
			public void run() {
				String a;
				try {
					for(;;){
						a = test.take();
						System.out.println("发现插入一个新的元素:" + a);
					}
				} catch (InterruptedException e) {
				}
			}
		}).start();

		new Thread(new Runnable() {

			@Override
			public void run() {
				try {
					for(;;){
						Thread.sleep(1000);
						System.out.println("插入新的元素");
						test.put("a");
					}
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}).start();
	}
}